<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="js/axios.js"></script>
    <title>首页</title>
</head>
<body>
   <form action="" method="get" id="loginForm">
       <label>用户名:<input type="text" id="account" name="account"></label><br>
       <label>密码:<input type="password" id="password" name="password"></label><br>
       <input type="submit" value="登录">
   </form>
    <script>
     let loginForm = document.getElementById("loginForm");
     let accountInput = document.getElementById("account");
     let passwordInput = document.getElementById("password");

     loginForm.addEventListener('submit',function (event) {
         event.preventDefault();//阻止表单的默认提交
         //构造要发送的参数对象
         const  data ={
             account : accountInput.value,
             password : passwordInput.value,
         }
         console.log(data);

         //发起异步请求
         axios.post('/login',data)
             .then(res => console.log(res.data) )
             .then(err => console.log("请求失败"))
     })
    </script>
</body>
</html>